package com.echoesnet.echoesshortvideo.Api;

import android.content.Context;
import android.content.Intent;

import com.echoesnet.echoesshortvideo.Activities.LoginAct;
import com.echoesnet.echoesshortvideo.AppController;
import com.echoesnet.echoesshortvideo.Utils.ToastUtils;

/**
 * Copyright (C) 2018 科技发展有限公司
 * 完全享有此软件的著作权，违者必究
 *
 * @author ben
 * @version 1.0
 * @modifier
 * @createDate 2018/4/24 11:21
 * @description
 */
public class ErrorCodeTable
{
    public static final String USR_LOGIN_TIMEOUT="USR_LOGIN_TIMEOUT";
    public static final String USR_TOK_NULL="USR_TOK_NULL";
    public static final String NOT_LOGIN ="NOT_LOGIN";//用户未登录
    public static final String NO_SAME_DEVICEID  ="NO_SAME_DEVICEID";//当前调用接口的设备号不是最后登录时的设备号
    public static final String USER_LOCKED  ="USER_LOCKED";//用户被锁定

    public static final String CODE_ERROR ="CODE_ERROR";
    public static final String CODE_INVALID ="CODE_INVALID";
    public static final String USER_NOT_EXITS ="USER_NOT_EXITS";
    public static final String USER_IS_EXITS ="USER_IS_EXITS";
    public static final String PASSWORD_ERROR  ="PASSWORD_ERROR";
    public static final String UNBOUND_MOBILE  ="UNBOUND_MOBILE";
    public static final String VIDEO_DELETED  ="VIDEO_DELETED";

    public static boolean handleSpecificError(String errorCode)
    {
         if (NOT_LOGIN.equals(errorCode)||NO_SAME_DEVICEID.equals(errorCode))
         {
             Context mContext= AppController.getInstance();
             Intent intent = new Intent(mContext, LoginAct.class);
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             mContext.startActivity(intent);
             return true;
         }else if (USER_LOCKED.equals(errorCode))
         {
             Context mContext= AppController.getInstance();
             Intent intent = new Intent(mContext, LoginAct.class);
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             mContext.startActivity(intent);
             ToastUtils.showLong("您的账户有违规行为，已被管理员封号");
             return true;
         }
         return false;
    }


    public static String parseErrorCode(String errorCode)
    {
        return  errorCode.equals(USR_LOGIN_TIMEOUT)?"手机验证码错误":
                errorCode.equals(CODE_ERROR)?"您输入的验证码有误，请核对后再输入。":
                errorCode.equals(CODE_INVALID)?"验证码失效":
                errorCode.equals(USER_NOT_EXITS)?"用户不存在":
                errorCode.equals(PASSWORD_ERROR)?"密码输入错误":
                errorCode.equals(USER_LOCKED)?"账户被锁定，部分高级功能受限":
                errorCode.equals(USER_IS_EXITS)?"用户已注册":
                errorCode.equals(VIDEO_DELETED)?"视频已删除":
                errorCode.equals("1")?"小饭也不知道怎么了，您可以重试一下下":


                errorCode;
    }
}
